package com.Interface.util;



import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;




/**
 * 
 * 
 * @author 
 */
public class ExportUtil {

	// 微信附件类型（image）、语音（voice）、视频（video）


	/**
	 * 下载文件
	 */
	public static boolean downlodad(String filePath, String fileName, HttpServletResponse response) {
		InputStream is = null;
		OutputStream os = null;
		try {
			File file = new File(filePath);
			is = new FileInputStream(file);
			os = response.getOutputStream();
			//设置下载信息
			//response.setContentType("application/vnd.ms-excel");
			response.setContentType("application/octet-stream");
			response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("GBK"), "ISO-8859-1"));
			byte[] b = new byte[1024 * 10];
			int len = 0;
			while ((len = is.read(b, 0, b.length)) != -1) {
				os.write(b, 0, len);
				os.flush();
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (is != null) try {is.close();} catch (Exception e) {}
			if (os != null) try {os.close();} catch (Exception e) {}
		}
		return true;
	}

}
